package mybag1;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;


public class UserServer {
    public static void main(String[] args) {
        ServerSocket server = null;
        Socket socket = null;
        ObjectInputStream reader = null;
        PrintWriter writer = null;
        try {
            server = new ServerSocket(1234);
            socket = server.accept();
            reader = new ObjectInputStream(socket.getInputStream());
            User user = (User) reader.readObject();
            String content = null;
            if (user != null && "gf".equals(user.getUsername()) && "gf".equals(user.getUsername())) {
                content = "登录成功!";
            } else {
                content = "登录失败!";
            }
            writer = new PrintWriter(socket.getOutputStream());
            writer.println(content);
            writer.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
                if (writer != null) {
                    writer.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
